#include <stdio.h>
#include <shadow.h>
#include <crypt.h>
#include <unistd.h>
#include <string.h>

int main (int argc, char **argv)
{
	struct spwd *gsp;
	char *pass;
	char *crypt_pw;
	//argv[1] --> user name
	if(argc < 2) {
		return -1;
	}
	gsp = getspnam (argv[1]);
	if (NULL == gsp) {
		perror ("getspnam()");
		return -1;
	}
	printf ("%s\n", gsp->sp_pwdp);
	
	//读取密码
	pass = getpass ("passwd:");
	//将读到的密码加密
	crypt_pw = crypt (pass, gsp->sp_pwdp);
	if (NULL == crypt_pw) {
		perror ("crypt");
		return -1;
	} 
	if (strcmp (crypt_pw, gsp->sp_pwdp) == 0) {
		printf ("密码正确\n");
	} else {
		printf ("密码错误\n");
	}
	return 0;
}
	
